﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import org.aswing.geom.*;

    public class WindowLayout extends EmptyLayout {

        public static const TITLE:String = "Title";
        public static const CONTENT:String = "Content";

        private var titleBar:Component;
        private var contentPane:Component;

        override public function addLayoutComponent(_arg1:Component, _arg2:Object):void{
            if (_arg2 == TITLE){
                this.titleBar = _arg1;
            } else {
                if (_arg2 == CONTENT){
                    this.contentPane = _arg1;
                } else {
                    throw (new ArgumentError(("ERROR When add component to JWindow/JFrame, constraints must be TITLE or CONTENT : " + _arg2)));
                };
            };
        }
        public function getTitleBar():Component{
            return (this.titleBar);
        }
        public function getContentPane():Component{
            return (this.contentPane);
        }
        override public function removeLayoutComponent(_arg1:Component):void{
            if (_arg1 == this.titleBar){
                this.titleBar = null;
            } else {
                if (_arg1 == this.contentPane){
                    this.contentPane = null;
                };
            };
        }
        override public function minimumLayoutSize(_arg1:Container):IntDimension{
            var _local2:Insets = _arg1.getInsets();
            var _local3:IntDimension = _local2.getOutsideSize();
            if (this.titleBar != null){
                _local3.increaseSize(this.titleBar.getMinimumSize());
            };
            return (_local3);
        }
        override public function preferredLayoutSize(_arg1:Container):IntDimension{
            var _local4:IntDimension;
            var _local5:IntDimension;
            var _local2:Insets = _arg1.getInsets();
            var _local3:IntDimension = _local2.getOutsideSize();
            if (this.titleBar != null){
                _local4 = this.titleBar.getPreferredSize();
            } else {
                _local4 = new IntDimension(0, 0);
            };
            if (this.contentPane != null){
                _local5 = this.contentPane.getPreferredSize();
            } else {
                _local5 = new IntDimension(0, 0);
            };
            _local3.increaseSize(new IntDimension(Math.max(_local4.width, _local5.width), (_local4.height + _local5.height)));
            return (_local3);
        }
        override public function layoutContainer(_arg1:Container):void{
            var _local5:IntDimension;
            var _local2:IntDimension = _arg1.getSize();
            var _local3:Insets = _arg1.getInsets();
            var _local4:IntRectangle = _local3.getInsideBounds(_local2.getBounds());
            if (this.titleBar != null){
                _local5 = this.titleBar.getPreferredSize();
                this.titleBar.setBounds(new IntRectangle(_local4.x, _local4.y, _local4.width, _local5.height));
                _local4.y = (_local4.y + _local5.height);
                _local4.height = (_local4.height - _local5.height);
            };
            if (this.contentPane != null){
                this.contentPane.setBounds(new IntRectangle(_local4.x, _local4.y, _local4.width, _local4.height));
            };
        }
        public function toString():String{
            return ("WindowLayout[]");
        }

    }
}//package org.aswing 
